{
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.2"
  },
  "orig_nbformat": 2,
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3",
   "language": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2,
 "cells": [
  {
   "source": [
    "# `if-else` 语句"
   ],
   "cell_type": "markdown",
   "metadata": {}
  },
  {
   "source": [
    "- 语法：\n",
    "    ```\n",
    "    if 条件表达式:\n",
    "        代码块\n",
    "    else:\n",
    "        代码块\n",
    "    ```\n",
    "- 流程： `if` 语句在执行时，会先对条件表达式进行求值判断\n",
    "    - 如果为 `True`，则执行 `if` 后的语句\n",
    "    - 如果为 `False`，则执行 `else` 后的语句\n",
    "    \n",
    "  "
   ],
   "cell_type": "markdown",
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "age = int(input('请输入你的年龄：'))\n",
    "if age >= 18:\n",
    "    print('你已经成年了')\n",
    "else:\n",
    "    print('你还未成年')"
   ]
  },
  {
   "source": [
    "## 练习"
   ],
   "cell_type": "markdown",
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "name = input('user name: ')\n",
    "\n",
    "if name == 'admin':\n",
    "    print(f'Welcome admin {name}!')\n",
    "else:\n",
    "    print(f'Welcome user {name}!')"
   ]
  }
 ]
}